package com.example.demo.t2.monad_t;


import java.util.stream.IntStream;
import java.util.stream.Stream;


public class Event<T> {
    private T data;
    public Event(T data) {
        this.data = data;
    }

    static class EventData {
        Integer id;
        String msg;

        public EventData(Integer id, String msg) {
            this.id = id;
            this.msg = msg;
        }

        @Override
        public String toString() {
            return "EventData{" +
                    "id=" + id +
                    ", msg='" + msg + '\'' +
                    '}';
        }
    }

    static class Transform {
        static EventData transform(Integer id) {
            switch (id) {
                case 0:
                    return new EventData(id, "新订单");
                case 1:
                    return new EventData(id, "已支付");
                case 2:
                    return new EventData(id, "已发货");
                case 3:
                    return new EventData(id, "交易成功");
                default:
                    return new EventData(5, "已退货");
            }
        }
    }

    @FunctionalInterface
    interface FN<A, B>{
        B apply(A a);
    }

    <B> Event<?> map(FN<T, B> fn) {
        return new Event(fn.apply(this.data));
    }

    public static void main(String[] args) {

        Stream<Event<Integer>> list = Stream.of(
                new Event(0),
                new Event(1),
                new Event(2),
                new Event(3),
                new Event(4)
        );
        list.map(o -> o.map(Transform::transform))
                .forEach(o -> System.out.println(o.data));

//        Stream<Event<Integer>>

    }
}
